package com.passer.uam.manager.index;

import com.passer.toolbox.common.password.encryption.Encrypt;
import com.passer.toolbox.common.file.util.FileUtils;
import com.passer.uam.config.UamConfig;
import com.passer.uam.entity.AccountIndex;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.Date;
import java.util.Optional;

@Slf4j
public class IndexManager {
    private final Encrypt encrypt = new Encrypt();

    public void saveIndex(AccountIndex index) {
        File folder = new File(UamConfig.getAccountIndexPath());
        if (!folder.exists() && !folder.mkdirs()) {
            log.error("索引保存文件夹创建失败");
            throw new RuntimeException("账号信息保存失败");
        }
        Optional<File> indexOptional = FileUtils.getNormalSizeFile(folder);
        File indexFile = indexOptional.orElse(new File(folder, new Date().getTime() + ""));
        String indexEncrypt = encrypt.encrypt(index.getId() + "," + index.getSource() + "," + index.getFilePath() + "," + index.getStart() + "," + index.getEnd() + "\n");

    }

}
